from sqlalchemy import create_engine
from time import strftime, localtime
from datetime import timedelta, date
import calendar
import tushare as ts

for x in range(7):
	print (x)
	tdate=date.today() - timedelta(days=x)
	print (tdate)
	df = ts.get_tick_data('300115', date=(date.today() - timedelta(days=x)).strftime('%Y-%m-%d'))
	engine = create_engine('postgresql://lengdh:123456@127.0.0.1:5432/postgres')

	#存入数据库
	# df.to_sql('tick_data',engine)

	#追加数据到现有表
	df.to_sql('tick_data_300115_'+tdate.strftime('%Y-%m-%d'),engine,if_exists='append')